/*
 * A simple ToDo Manager
 *
 * Copyright (c) 2011 Nosheen Zaza, Manuel Rebollo, Seyedsaeid Mahpeikar and
 * Wo Ke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package todomanager.ui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JProgressBar;
import javax.swing.JPanel;

/**
 * This class creates a progress meters with two buttons on the sides to
 * increase or decerase progress.
 * 
 * @author Manuel Rebollo
 */
public class ProgressMeter extends JPanel {

    private JProgressBar progressBar;
    private JButton increaseButton;
    private JButton decreaseButton;

    /**
     *  The constructor of the class
     */
    public ProgressMeter() {
        super(new BorderLayout());
        // progress bar
        progressBar = new JProgressBar(0, 10);
        // Increase progress button
        IncProgressAction inc = new IncProgressAction();
        increaseButton = new JButton(inc);
        add(increaseButton, BorderLayout.EAST);

        // Decrease progress button
        DecProgressAction dec = new DecProgressAction();
        decreaseButton = new JButton(dec);
        add(decreaseButton, BorderLayout.WEST);


        add(progressBar, BorderLayout.CENTER);
    }

    /**
     * Creates an instance of this class with the given progress.
     * @param progress
     */
    public ProgressMeter(int progress) {
        this();
        progressBar.setValue(progress);
    }

    /**
     * Sets the progress of the progress bar.
     * @param progress
     */
    public void setProgress(int progress) {
        progressBar.setValue(progress);
    }

    /**
     * Returns the increase button.
     * @return
     */
    public JButton getIncreaseButton() {
        return increaseButton;
    }

    /**
     * Returns the decrease button.
     * @return
     */
    public JButton getDecreaseButton() {
        return decreaseButton;
    }

    /**
     * Returns the progress bar.
     * @return
     */
    public JProgressBar getProgressBar() {
        return progressBar;
    }

     /**
      * Advances the progress bar
      */
    public class IncProgressAction extends AbstractAction {
        /**
         * Creates a new instance of this class.
         */
        public IncProgressAction() {

            super("+");
        }

        /**
         * Increments the value of the progress bar by one.
         * @param e
         */
        public void actionPerformed(ActionEvent e) {
            progressBar.setValue(progressBar.getValue() + 1);
        }
    }

    /**
     * Decrements the value of the progress bar.
     */
    public class DecProgressAction extends AbstractAction {

        /**
         * Sets the progress bar that is under this action's control.
         */
        public DecProgressAction() {

            super("-");
        }

        /**
         * Decrements the value of the progress bar.
         * @param e
         */
        public void actionPerformed(ActionEvent e) {
            progressBar.setValue(progressBar.getValue() - 1);
        }
    }

  
}
